package gui;

import collector.Chain;
import collector.Collector;

import java.text.DecimalFormat;
import java.util.ArrayList;

/**
 * @author dotekien
 *         Date: Mar 31, 2006
 *         Time: 4:45:35 PM
 */
public class ChainTableModel extends SameTableModel {
    public static final String[] TOOL_TIPS = new String[]{
            "",
            "",
            "Number of duplicated chunks",
            "Number of statements in one chunk",
            "Percentage duplication on total statements of the project",
    };
    private final ArrayList<Chain> chains;
    private final Collector collector;

    public ChainTableModel(Collector collector, ArrayList<Chain> chains) {
        this.chains = chains;
        this.collector = collector;
        /*Chain number,
number of duplicated times (or number of chunk inside),
duplicated percentage compared with number of statement (how many percentage of code this chunk covered),
number of files in chain (how many files contain the same chunk),
How long for a chunk or the number of statement*/
        columnNames = new String[]{"ID",
                "Chains",
                "NDC",
                "NSC",
                "Percentage"
        };
        types = new Class[]{
                Number.class,
                Object.class,
                Number.class,
                Number.class,
                Number.class};

        fillData(); //to fill data array
    }

    private void fillData() {
        int row = chains.size();
        int col = getColumnCount();
        data = new Object[row][col];
        int allS = collector.getProjectNumOfStatement();
        DecimalFormat df = new DecimalFormat("###.##");
        for (int i = 0; i < row; i++) {
            Chain tmp = chains.get(i);
            int noc = tmp.getNumberOfChunks();
            int nos = tmp.getNumberOfStatement();

            data[i][0] = tmp.getId();
            data[i][1] = tmp.toStringForTable();
            data[i][2] = noc; //duplicated times or how many chunks we have

            data[i][3] = nos;
            data[i][4] = new Double(df.format(100.0 * nos * noc / allS));
        }
    }
}
